package com.dondedesigns.eh.persistence.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.hibernate.transform.ResultTransformer;

import com.dondedesigns.eh.persistence.AliveStatus;
import com.dondedesigns.eh.persistence.BlUser;

public class BlUserDAO extends GenericDAO<BlUser> {

	public BlUser findByUsername(String blUsername) {
		Session s = (Session) getEntityManager().getDelegate();
		BlUser blUser = (BlUser) s.createCriteria(BlUser.class)
			.add(Restrictions.eq("username", blUsername)).uniqueResult();
			
		return blUser;
	}

	public BlUser find(Long parseLong) {
		return super.find(BlUser.class, parseLong);
	}

	
	@SuppressWarnings("unchecked")
	public List<BlUser> selectAlive() {
		Session s = (Session) getEntityManager().getDelegate();
		List<BlUser> blUsers = s.createCriteria(BlUser.class)
			.add(Restrictions.eq("aliveStatus", AliveStatus.ALIVE))
			.addOrder(Order.asc("username"))
			.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
			.list();
			
		return blUsers;
	}

	
	
}
